package com.mmy.controller.guide;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mmy.domain.guide.VGuideInfo;
import com.mmy.domain.sys.TSysOrg;
import com.mmy.service.impl.guide.VGuideInfoServiceImpl;
import com.mmy.service.impl.sys.TSysOrgServiceImpl;

@Controller
public class VGuideInfoController {
	@Autowired
	VGuideInfoServiceImpl vGuideInfoServiceImpl;
	@Autowired
	TSysOrgServiceImpl tSysOrgServiceImpl;

	/* 进入后台用户首页 */
	@RequestMapping(value = "/guideindex")
	public String findAllGuide(Model m) {
		List<VGuideInfo> db_VGuideInfo = vGuideInfoServiceImpl.findAll();
		m.addAttribute("newVGuideInfo", db_VGuideInfo);
		/* 查询所有公司 */
		List<TSysOrg> db_TSysOrg = tSysOrgServiceImpl.findAll();
		m.addAttribute("newTSysOrg", db_TSysOrg);

		return "webbackground/guidemanagement/guideindex";
	}

	/* 进入导游详情页面 */
	@RequestMapping(value = "/guideinfo")
	public String ToGuideInfo(HttpServletRequest request, Model model) {

		int iGuideID = Integer.parseInt(request.getParameter("GuideID"));

		VGuideInfo vGuideInfo = vGuideInfoServiceImpl.findByID(iGuideID);
		model.addAttribute("newVGuideInfo", vGuideInfo);

		return "webbackground/guidemanagement/guideinfo";
	}

	/**
	 * 函数功能说明： 查询导游信息
	 *
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 shangzl
	 * @date 创建日期 2020-08-06
	 */
	@RequestMapping(value = "/searchguide")
	public String FindGuideInfo(HttpServletRequest request, Model model) {

		String strGuideName = request.getParameter("GuideName");
		String strSex = request.getParameter("Sex");
		String strGuideLevel = request.getParameter("GuideLevel");
		String strLanguage = request.getParameter("Language");
		String strOrgID = request.getParameter("OrgID");
		List<VGuideInfo> db_VGuideInfo = new ArrayList<VGuideInfo>();

		if (strGuideName == "" && strSex == "" && strGuideLevel == "" && strLanguage == "" && strOrgID == "") {

			db_VGuideInfo = vGuideInfoServiceImpl.findAll();
		} else {
			db_VGuideInfo = vGuideInfoServiceImpl.findSearch(strGuideName, strSex, strGuideLevel, strLanguage,
					strOrgID);

		}
		model.addAttribute("newVGuideInfo", db_VGuideInfo);
		/* 查询所有旅行社 */
		List<TSysOrg> db_TSysOrg = tSysOrgServiceImpl.findAll();
		model.addAttribute("newTSysOrg", db_TSysOrg);
		return "webbackground/guidemanagement/guideindex";
	}

}
